package com.ushine.web.component.mapstruct.model.data;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.ushine.web.base.model.system.DataPermissionDO;
import com.ushine.web.base.model.system.FunctionPermissionDO;
import com.ushine.web.base.model.system.RoleDO;
import com.ushine.web.base.model.system.UserGroupDO;
import io.swagger.annotations.ApiModelProperty;
import lombok.AccessLevel;
import lombok.Data;
import lombok.Getter;
import org.hibernate.validator.constraints.Length;
import org.springframework.data.annotation.CreatedBy;

import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.Transient;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Pattern;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
import java.util.Set;

/**
 * @Author: yls
 * @Date: 2021/3/3 9:33
 * @Description: 用户模型表，这里只是测试，不建数据库表
 * @Version 1.0
 */
//@Entity
@Data
//@ApiModel(description = "用户模型表")
//@Table(name = "t_model_user")
//@org.hibernate.annotations.Table(appliesTo = "t_model_user", comment = "用户模型表")
//@TableName(value = "t_model_user")
//@EntityListeners(AuditingEntityListener.class)
public class UserModelDO implements Serializable {
    /**
     * 编号
     * // 解决前台js接收雪花id精度丢失问题
     * <p>
     * JsonFormat(shape = JsonFormat.Shape.STRING)
     */
    @Id
    @CreatedBy
    @TableId(type = IdType.ASSIGN_ID)
    @ApiModelProperty("编号")
    @JsonFormat(shape = JsonFormat.Shape.STRING)
    @Column(name = "id", columnDefinition = "bigint comment '编号'")
    private Long id;

    /**
     * 用户名
     */
    @ApiModelProperty("用户名")
    @Column(name = "username", columnDefinition = "varchar(32) comment '用户名'")
    @NotBlank(message = "用户名不能为空")
    @Length(max = 32, message = "用户名最大长度为：32")
    private String username;

    /**
     * 密码
     */
    @ApiModelProperty("密码")
    @Column(name = "password", columnDefinition = "varchar(255) comment '密码'")
    @Length(max = 255, message = "密码最大长度为：255")
    private String password;

    /**
     * 用户是否过期，未过期：true，过期：false
     */
    @Getter(value = AccessLevel.NONE)
    @Column(name = "account_non_expired", columnDefinition = "tinyint default 1  comment '用户是否过期，未过期：true，过期：false'")
    private Boolean accountNonExpired;

    /**
     * 用户是否被锁定，未锁定：true，锁定：false
     */
    @Getter(value = AccessLevel.NONE)
    @Column(name = "account_non_locked", columnDefinition = "tinyint default 1  comment '用户是否被锁定，未锁定：true，锁定：false'")
    private Boolean accountNonLocked;

    /**
     * 用户的密码是否已过期，未过期：true，过期：false
     */
    @Getter(value = AccessLevel.NONE)
    @Column(name = "credentials_non_expired", columnDefinition = "tinyint default 1 comment '用户的密码是否已过期，未过期：true，过期：false'")
    private Boolean credentialsNonExpired;

    /**
     * 用户是否禁用，未禁用：true，禁用：false
     */
    @Getter(value = AccessLevel.NONE)
    @Column(name = "enabled", columnDefinition = "tinyint default 1  comment '用户是否禁用，未禁用：true，禁用：false'")
    private Boolean enabled;

    /**
     * 显示名称
     */
    @ApiModelProperty("真实姓名")
    @Column(name = "true_name", columnDefinition = "varchar(32) comment '显示名称'")
    @NotBlank(message = "真实姓名不能为空")
    @Length(max = 32, message = "真实姓名最大长度为：32")
    private String trueName;

    /**
     * 状态
     */
    @ApiModelProperty("状态")
    @Column(name = "status", columnDefinition = "tinyint comment '状态'")
    private Integer status;

    /**
     * 最后登录时间
     */
    @ApiModelProperty("最后登录时间")
    @Column(name = "last_login_time", columnDefinition = "datetime comment '最后登录时间'")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date lastLoginTime;


    /**
     * 所属省
     */
    @ApiModelProperty("所属国")
    @Column(name = "country", columnDefinition = "varchar(16) comment '所属国'")
    @Length(max = 16, message = "所属市国最大长度为：16")
    private String country;

    /**
     * 所属省
     */
    @ApiModelProperty("所属省")
    @Column(name = "province", columnDefinition = "varchar(32) comment '所属省'")
    @Length(max = 32, message = "所属省最大长度为：32")
    private String province;

    /**
     * 所属市
     */
    @ApiModelProperty("所属市")
    @Column(name = "city", columnDefinition = "varchar(32) comment '所属市'")
    @Length(max = 32, message = "所属市最大长度为：32")
    private String city;

    /**
     * 所属单位
     */
    @ApiModelProperty("所属单位")
    @Column(name = "company", columnDefinition = "varchar(32) comment '所属单位'")
    @Length(max = 32, message = "所属单位最大长度为：32")
    private String company;


    /**
     * 电话
     */
    @ApiModelProperty("电话")
    @Column(name = "mobile", columnDefinition = "varchar(16) comment '电话'")
    @Pattern(regexp = "^(\\S*|1[0-9]{10})$", message = "手机号码格式有误")
    @Length(max = 16, message = "所属单位最大长度为：16")
    private String mobile;

    /**
     * 特殊编号
     */
    @ApiModelProperty("特殊编号")
    @Column(name = "user_id", columnDefinition = "varchar(32) comment '特殊编号'")
    @Length(max = 32, message = "特殊编号最大长度为：32")
    private String userId;

    /**
     * 备注
     */
    @ApiModelProperty("备注")
    @Column(name = "remarks", columnDefinition = "varchar(255) comment '备注'")
    @Length(max = 255, message = "备注最大长度为：255")
    private String remarks;

    /**
     * 逻辑删除
     * TableField => select:false (在查询的时候排除该字段)
     */
    @TableLogic
    @TableField(value = "is_deleted", fill = FieldFill.INSERT, select = false)
    @ApiModelProperty(value = "逻辑删除", example = "2020-02-02 12:00:00")
    @Column(name = "is_deleted", columnDefinition = "datetime comment '删除标记=> 不为null：已删除，为空：未删除'")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private LocalDateTime deleted;
    
    /**
     * 所属组织
     */
    @Transient
    @TableField(exist = false)
    @ApiModelProperty("组织")
    private OrgModelDO orgModelDO;

    /**
     * 角色名称
     */
    @Transient
    @TableField(exist = false)
    @ApiModelProperty("角色")
    private Set<String> roleNames;

    /**
     * 认证信息
     */
    @Transient
    @TableField(exist = false)
    @ApiModelProperty("认证信息")
    private String token;

    /**
     * 用户组名称
     */
    @Transient
    @TableField(exist = false)
    @ApiModelProperty("用户组")
    private Set<String> userGroupNames;

    /**
     * 角色集合
     */
    @Transient
    @TableField(exist = false)
    @ApiModelProperty("角色")
    private List<RoleDO> roles;

    /**
     * 用户组集合
     */
    @Transient
    @TableField(exist = false)
    @ApiModelProperty("用户组")
    private List<UserGroupDO> userGroups;

    /**
     * 操作权限
     */
    @Transient
    @TableField(exist = false)
    @ApiModelProperty("操作权限")
    private List<FunctionPermissionDO> functionPermissions;

    /**
     * 数据权限
     */
    @Transient
    @TableField(exist = false)
    @ApiModelProperty("数据权限")
    private List<DataPermissionDO> dataPermissions;


}
